package com.mes.web.controller.tdd;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.google.gson.Gson;
import com.mes.entity.cb.OrderDetailed;
import com.mes.entity.tdd.YearNumUtil;
import com.mes.entity.tdd.tj.Tpage;
import com.mes.service.tdd.ReportDService;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;

/**
 * 
 * @ClassName:StaffController
 * @Description:员工信息
 * @Author tdd
 * @Date 2018年3月22日上午11:22:24
 * @version 1.0
 */
@Controller
@RequestMapping("/reportD")
public class ReportDController {
	@Resource ReportDService reportDService;
	/**
	 * 员工分页列表查询
	 * @param pageBean 分页+条数
	 * @param limit 每页条数
	 * @param offset 条数
	 * @param response response对象
	 * @throws Exception 异常
	 */
	@RequestMapping("/caigouOrderReportList")
	public void caigouOrderReportList(HttpServletRequest request,Tpage pageBean,@RequestParam(value="limit",required=false)String limit,@RequestParam(value="offset",required=false)String offset,HttpServletResponse response) throws Exception {
		//页数
		pageBean.setPage(Integer.parseInt(offset)/Integer.parseInt(limit)+1);
		//每页条数
		pageBean.setPageSize(Integer.parseInt(limit));
		//是否删除：未删除
		pageBean.setIsdelete("0");
		//员工分页列表查询
		List<OrderDetailed> staffs=reportDService.caigouOrderReportFindPageByMution(pageBean);
		//员工总条数
		int total=reportDService.caigouOrderReportSelectCountByMution(pageBean);
		//员工分页列表查询 和总条数传递到jsp
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
		JSONArray jsonArray = JSONArray.fromObject(staffs, jsonConfig);
		jsonObject.put("total", total);
		jsonObject.put("rows", jsonArray);
		ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 查询当前年每月资材入库数量
	 * @param response response对象
	 * @throws Exception 异常
	 */
	@RequestMapping("/rkYearNum")
	public void rkYearNum(HttpServletResponse response) throws Exception{
		List<YearNumUtil> list=reportDService.rkYearNum();
		Gson gson = new Gson();
		ResponseUtil.write(response, gson.toJson(list));
	}
	/**
	 * 查询当前年每月资材退货数量
	 * @param response response对象
	 * @throws Exception 异常
	 */
	@RequestMapping("/returnYearNum")
	public void returnYearNum(HttpServletResponse response) throws Exception{
		List<YearNumUtil> list=reportDService.returnYearNum();
		Gson gson = new Gson();
		ResponseUtil.write(response, gson.toJson(list));
	}
}
